package cn.cslg.tieba.service.impl;

import cn.cslg.tieba.domain.dao.UserDao;
import cn.cslg.tieba.domain.entity.User;
import cn.cslg.tieba.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Wu Zhenwei
 * 2017/11/21
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User login(User user) {
        User data = userDao.findById(user.getUserId());
        if (data != null && data.getPassword().equals(user.getPassword())) {
            data.setPassword(null);
            return data;
        }
        return null;
    }

    @Override
    public User register(User user) {
        userDao.insert(user);
        user.setPassword(null);
        return user;
    }

}
